package me.sealer.ssm.controller;

import me.sealer.ssm.controller.dto.CommonResponse;
import me.sealer.ssm.entity.drools.Consumer;
import me.sealer.ssm.entity.drools.PriceResult;
import org.kie.api.runtime.KieSession;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigInteger;

/**
 * 功能描述： $ TestController
 *
 * @author sealer
 * @email 1178884049@qq.com
 * @date 2020年01月19日 12时32分35秒
 */
@RestController
@RequestMapping(value = "/price")
public class TestController {
    @Resource
    private KieSession kieSession;

    @RequestMapping("/vip")
    public CommonResponse vip() {
        Consumer consumer = new Consumer();
        consumer.setVip(true);

        PriceResult result = new PriceResult();
        result.setPrice(100);

        kieSession.insert(consumer);
        kieSession.insert(result);
        int ruleFiredCount = kieSession.fireAllRules();
        System.out.println("触发了" + ruleFiredCount + "条规则");
        System.out.println("价格是: " + result.getPrice());

        return new CommonResponse();
    }

    @RequestMapping("/non-vip")
    public CommonResponse nonVip() {
        Consumer consumer = new Consumer();
        consumer.setVip(false);

        PriceResult result = new PriceResult();
        result.setPrice(100);

        kieSession.insert(consumer);
        kieSession.insert(result);
        int ruleFiredCount = kieSession.fireAllRules();
        System.out.println("触发了" + ruleFiredCount + "条规则");
        System.out.println("价格是: " + result.getPrice());

        return new CommonResponse();
    }
}
